package xx.thymeleaf.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import xx.thymeleaf.entity.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Classname HaloController
 * @Description TODO
 * @Date 2023/7/12 16:12
 * @Created by wangxianlin
 */
@RestController
public class HaloController {

    @GetMapping("index")
    public ModelAndView toIndex(){

        // 跳转页面
        ModelAndView model = new ModelAndView("/Helo");
        // 字符串
        model.addObject("data","SpringBoot 集成 Thymeleaf 模版!");

        User user = new User();
        user.setId(1);
        user.setName("张三");
        user.setPhone("13700000000");
        user.setAddress("北京市亦庄经济开发区");
        // 对象属性
        model.addObject("user",user);

        // 赋值一个CSS
        model.addObject("css","container");

        // list 集合
        List<User> userList = new ArrayList<User>();
        for (int i = 0;i < 3;i++){
            User u = new User();
            u.setId(100 + i);
            u.setName("张" + i);
            u.setPhone("1361234567" + i);
            u.setAddress("北京市大兴区" + i);
            userList.add(u);
        }
        model.addObject("userList",userList);

        // map
        Map<Integer,Object> userMaps = new HashMap<Integer, Object>(3);
        for (int i = 0;i < 3;i++){
            User u = new User();
            u.setId(100 + i);
            u.setName("张" + i);
            u.setPhone("1361234567" + i);
            u.setAddress("北京市大兴区" + i);
            userMaps.put(i,u);
        }
        model.addObject("userMaps",userMaps);

        // if 判断值
        model.addObject("ifData",1);




        return model;
    }

}
